package com.hjx.multidsmanger.controller;

import java.util.List;

import com.hjx.multidsmanger.mapper.ds3307.DS3307Mapper;
import com.hjx.multidsmanger.mapper.ds3308.DS3308Mapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ds")
public class TestController {

	/**
	 * 基于jdbcTemplate的方式指定数据源
	 */
	@Qualifier("ds1JdbcTemplate")
	@Autowired JdbcTemplate ds1JdbcTemplate;

	@Qualifier("ds2JdbcTemplate")
	@Autowired JdbcTemplate ds2JdbcTemplate;

	@RequestMapping("/1")
	public List<String> getDataFromDS1ByJdbcTemplate(){
		return ds1JdbcTemplate.queryForList("select username from users", String.class);
	}

	@RequestMapping("/2")
	public List<String> getDataFromDS2ByJdbcTemplate(){
		return ds2JdbcTemplate.queryForList("select name from user", String.class);
	}

	/**
	 * 基于配置mapper数据源的方式指定数据源
	 */

	@Autowired DS3307Mapper ds3307Mapper;
	@Autowired DS3308Mapper ds3308Mapper;

	@RequestMapping("/11")
	public List<String> getDataFromDS1(){
		return ds3307Mapper.selectList();
	}

	@RequestMapping("/22")
	public List<String> getDataFromDS2(){
		return ds3308Mapper.selectList();
	}
}
